#include "output_hepu.h"
#include "../../config/app_config.h"

OutputerHePu::OutputerHePu()
{

}

OutputerHePu::~OutputerHePu()
{

}

void OutputerHePu::UpdateRadarDeletedId(unsigned int id)
{
    hepu_one_target target;
    memset(&target, 0, sizeof(hepu_one_target));

    InitHeader(target.header);

    target.target.target_id = id;
    target.target.flag = 1;

    Send((char*)&target, sizeof(hepu_one_target));
}

void OutputerHePu::UpdateRadarInfo(const radar_info* info)
{
    /*if (info->move_status != 2)
    {
        return;
    }*/

    /*if (info->speed > sln_app_config::instance().get_hepu_speed_max())
    {
        return;
    }

    double quality = ((double)info->numberOfVisibleFrame / (double)info->history) * 100.0;
    if (quality < sln_app_config::instance().get_hepu_quality_min())
    {
        return;
    }

    if (info->speed_variance.GetDataVariance() > sln_app_config::instance().get_hepu_speed_variance())
    {
        return;
    }

    if (info->dir_rate_of_change.GetRateOfChange() > sln_app_config::instance().get_hepu_heading_rotate_max())
    {
        return;
    }*/

    hepu_one_target target;
    memset(&target, 0, sizeof(hepu_one_target));

    InitHeader(target.header);

    target.target.target_id = info->radar_id;
    target.target.altitude = info->altitude;
    target.target.azimuth = info->a;
    target.target.device_id = 0;
    target.target.evimuth = info->e;
    target.target.flag = 0;
    target.target.heading = info->heading;
    target.target.latitude = info->latitude;
    target.target.longitude = info->longitude;
    target.target.radial_speed = info->speed;
    target.target.range = info->r;
    target.target.timestramp = info->timestamp;
    target.target.visible_num = info->numberOfVisibleFrame;

    Send((char*)&target, sizeof(hepu_one_target));
}

void OutputerHePu::InitHeader(hepu_data_header &header)
{
    header.header[0] = 0x77;
    header.header[1] = 0xff;
    header.header[2] = 0xcc;
    header.header[3] = 0xcc;
    header.header[4] = 0xff;
    header.header[5] = 0x77;

    header.target_count = 1;
}
